/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState) {
  const { currentUser } = initialState;
  const hasRoutes = currentUser?.hasRoutes || [];
  return {
    canAdmin: currentUser && currentUser.access === 'admin',
    normalRouteFilter: (route) => {
      const {path} = route;
      const code = path.replace(/\//g, '-')?.substring(1);
      return hasRoutes.includes(code)
    }
  };
}
